package com.dtw.ditouwang.ui.mine

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.dtw.ditouwang.R
import com.dtw.ditouwang.beans.HelpBeanList
import com.dtw.ditouwang.ui.BaseActivity
import com.dtw.ditouwang.ui.OnItemClickListener
import kotlinx.android.synthetic.main.activity_help_list.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class HelpListActivity: BaseActivity(), OnItemClickListener {
    var helpBeanList=ArrayList<HelpBeanList.DataBean>()
    var helpListAdapter=HelpListAdapter(helpBeanList)

    override fun onItemClick(resID: Int, position: Int, state: Int) {
        var intent=Intent(this,HelpContentActivity::class.java)
        intent.putExtra(HelpContentActivity.KeyHelpConentID,helpBeanList[position].id.toString())
        startActivity(intent)
    }

    companion object {
        var KeyListID="KeyListID"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_help_list)
        enableBack()
        setTitle("帮助中心")
        helpListAdapter.onItemClickListener=this
        recyclerView.layoutManager=LinearLayoutManager(this)
        recyclerView.adapter=helpListAdapter

        webApi.getHelpList(intent.getStringExtra(KeyListID)).enqueue(object :Callback<HelpBeanList>{
            override fun onResponse(call: Call<HelpBeanList>, response: Response<HelpBeanList>) {
                var helpBeanList=response.body();
                if(helpBeanList!=null){
                    this@HelpListActivity.helpBeanList.addAll(helpBeanList.data)
                    helpListAdapter.notifyDataSetChanged()
                }
            }

            override fun onFailure(call: Call<HelpBeanList>, t: Throwable) {
                showToast("网络异常")
            }
        })
    }
}